package com.woniu.controller;

import com.woniu.entity.RbacRole;
import com.woniu.entity.ResponseEntity;
import com.woniu.service.RbacRoleService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:陈涵
 * @Do:
 * @date: 2022/9/7 6:54
 */
@RestController
@RequestMapping("/rbacRole")
@CrossOrigin
public class RbacRoleController {
    @Autowired
    RbacRoleService rbacRoleService;
//    @RequiresPermissions(logical = Logical.OR, value = {"role:findAll","admin"})
    @GetMapping("/")
    public ResponseEntity findAll(){
        return rbacRoleService.findAll();
    }

    @GetMapping("/findAllWithPage/{currentPage}/{pageSize}")
    public ResponseEntity findAllWithPage(@PathVariable("currentPage") Integer currentPage,@PathVariable("pageSize") Integer pageSize){
        return rbacRoleService.findAllWithPage(currentPage,pageSize);
    }
    @GetMapping("/{id}")
    @RequiresPermissions({"role:findOne","admin"})
    public ResponseEntity findOne(@PathVariable("id") int id){
        return rbacRoleService.findOne(id);
    }
    @PostMapping("/")
    @RequiresRoles(logical = Logical.OR,value={"role:addOne","admin"})
    public ResponseEntity addOne(@RequestBody RbacRole rbacRole){
        return rbacRoleService.addOne(rbacRole);
    }
    @DeleteMapping("/{id}")
//    @RequiresPermissions({"role:deleteOne","admin"})
    public ResponseEntity deleteOne(@PathVariable int id){
        return rbacRoleService.deleteOne(id);
    }
    @PutMapping("/")
    public ResponseEntity updateOne(@RequestBody RbacRole rbacRole){
        return rbacRoleService.updateOne(rbacRole);
    }

    @PutMapping("/editstatus/{id}/{status}")
    public ResponseEntity editstatus(@PathVariable("id") Integer id, @PathVariable("status") String status){
        return rbacRoleService.editstatus(id,status);
    }
}
